import request from '../utils/request';
import { PAGE_SIZE } from '../constants';

export function fetch({ page,sorter,filters }) {
  let orderItems=[]
  if (sorter){
    orderItems.push({FieldName:sorter.field?sorter.field:sorter.columnKey,
      Direction:sorter.order==="descend"?"DESC":"ASC"})
  }
  var data = new FormData()
  data.append("OrderItems",JSON.stringify(orderItems))
  return request(`/api/Find/User/${page}/${PAGE_SIZE}`,{
    method: 'POST',
    body:data,
  });
}

export function fetchOrganization() {
  return request(`/api/FindAll/Organization`,{
    method: 'POST'
  });
}

export function fetchPosition() {
  return request(`/api/FindAll/Position`,{
    method: 'POST'
  });
}

export function fetchSerial() {
  return request(`/api/FindAll/Serial`,{
    method: 'POST'
  });
}

export function remove(ids) {
  var data = new FormData()
  data.append('PrimaryKeyValues',JSON.stringify(ids))
  return request(`/api/Deletes/User`, {
    method: 'POST',
    body:data
  });
}

export function patch(values) {
  var data = new FormData()
  data.append('Entity',JSON.stringify(values))
  return request(`/api/Update/User`, {
    method: 'POST',
    body: data,
  });
}

// export function create(values) {
//    var data = new FormData()
//   data.append('Entity',JSON.stringify(values))
//   return request('/api/Add/User', {
//     method: 'POST',
//     body: data,
//   });
// }
